package com.yuanchuang.yp.mall.web.admin.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yuanchuang.yp.mall.web.admin.entity.AuthMenuDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜单 Mapper 接口
 * </p>
 *
 * @author mg-mybatis-generator
 * @since 2019-07-11
 */
public interface AuthMenuMapper extends BaseMapper<AuthMenuDO> {
    /**
     * 查询用户的所属菜单
     *
     * @param userId
     * @return
     */
    @Select("SELECT\n" +
            "  *\n" +
            "FROM\n" +
            "  auth_menu\n" +
            "WHERE id IN\n" +
            "  (SELECT\n" +
            "    auth_menu_id\n" +
            "  FROM\n" +
            "    auth_role_menu_rel\n" +
            "  WHERE auth_role_id IN\n" +
            "    (SELECT\n" +
            "      auth_role_id\n" +
            "    FROM\n" +
            "      auth_role_user_rel\n" +
            "    WHERE auth_user_id = ${userId}))")
    List<AuthMenuDO> listMenus(@Param("userId") Long userId);

}
